<template>
  <view class="order-detail">
    <view class="header">
      <view class="store-info">
        <view class="store-name">{{ order.supplier.name }}</view>
        <view class="store-address">
          <uni-icons type="location-filled" size="16" color="#666"></uni-icons>
          {{ order.storeAddress }}
        </view>
      </view>
      <view class="distance">店铺</view>
    </view>

    <view class="card">
      <view class="card-title">
        <uni-icons type="info" size="16" color="#ffb000"></uni-icons>
        <text>订单信息</text>
      </view>
      <view class="card-content">
        <view class="info-item">
          <text class="label">订单号：</text>
          <text class="value">{{ order.orderNo }}</text>
        </view>
        <view class="info-item">
          <text class="label">下单时间：</text>
          <text class="value">{{ order.createTime }}</text>
        </view>
        <view class="info-item">
          <text class="label">预计送达：</text>
          <text class="value highlight">{{ order.mealtime }}</text>
        </view>
        <view class="info-item">
          <text class="label">配送费：</text>
          <text class="value">¥{{ order.takeFee }}</text>
        </view>
      </view>
    </view>

    <view class="card">
      <view class="card-title">
        <uni-icons type="person" size="16" color="#ffb000"></uni-icons>
        <text>客户信息</text>
      </view>
      <view class="card-content">
        <view class="info-item">
          <text class="label">姓名：</text>
          <text class="value">{{ order.user.nickName }}</text>
        </view>
        <view class="info-item">
          <text class="label">电话：</text>
          <text class="value">{{ order.user.mobile }}</text>
        </view>
        <view class="info-item">
          <text class="label">地址：</text>
          <text class="value">{{order.orderAddress?.detail || '暂无地址信息' }}</text>
        </view>
      </view>
    </view>
    
    <view class="card" v-if="order.deliverStatus === 3 || order.deliverStatus === 4">
      <view class="card-title">
        <uni-icons type="flag" size="16" color="#ffb000"></uni-icons>
        <text>配送进度</text>
      </view>
      <view class="card-content">
        <view class="delivery-steps">
          <view class="step" :class="{active: true}">
            <uniIcon class="step-icon" type="sound" size="16" color="white"></uniIcon>
            <view class="step-content">
              <text class="step-title">到店取餐</text>
              <text class="step-time">{{order.deliverStatus === 2 ? '进行中' : '已完成' }}</text>
            </view>
          </view>
          <view class="step" :class="{active: order.deliverStatus === 2 || order.deliverStatus === 3 || order.deliverStatus === 4}">
            <uniIcon class="step-icon" type="paperplane" size="16" color="white"></uniIcon>
            <view class="step-content">
              <text class="step-title">配送中</text>
              <text class="step-time">{{order.deliverStatus === 2 || order.deliverStatus === 4  ? '进行中' : '已完成' }}</text>
            </view>
          </view>
          <view class="step" :class="{active: order.deliverStatus === 4, completed: order.deliverStatus === '已完成'}">
            <uniIcon class="step-icon" type="compose" size="16" color="white"></uniIcon>
            <view class="step-content">
              <text class="step-title">已送达</text>
              <text class="step-time">{{ order.completedTime || (order.deliverStatus === 4 ? '已完成' : '待完成') }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="action-buttons" v-if="order.deliverStatus === 1">
      <button class="btn btn-primary" @click="arriveStore">
  <uniIcon type="eye" size="16" color="white"></uniIcon>
  到店取餐
</button>
<button class="btn btn-secondary" @click="contactCustomer">
  <uniIcon type="phone" size="16" color="#333"></uniIcon>
  联系客户
</button>
    </view>
    <view class="action-buttons" v-else-if="order.deliverStatus === 3 || order.deliverStatus === 4">
      <button class="btn btn-secondary" @click="contactCustomer">
  <uniIcon type="phone" size="16" color="#333"></uniIcon>
  联系客户
</button>
    </view>
  </view>
</template>

<script>
import uniIcon from "@/components/uni-icon/uni-icon.vue"
export default {
  components: {uniIcon},
  data() {
    return {
      order: {
        id: '123456789',
        storeName: '麦当劳(王府井店)',
        storeAddress: '北京市东城区王府井大街88号',
        distance: 1.5,
        createTime: '2023-06-15 12:30:45',
        expectedTime: '2023-06-15 13:30:00',
        deliveryFee: 8.5,
        customerName: '张先生',
        customerPhone: '138****1234',
        customerAddress: '北京市东城区东长安街1号东方广场E1座18层',
        status: '待抢单',
      }
    }
  },
  methods: {
    arriveStore() {
      uni.navigateTo({
        url: '/pages/rider/order/riderDelivering?order=' + JSON.stringify(this.order)
      });
      uni.showToast({
        title: '已到达商家，请取餐',
        icon: 'success'
      })
    },
    contactCustomer() {
      uni.makePhoneCall({
        phoneNumber: this.order.customerPhone
      })
    }
  },
  onLoad(options) {
    if (options.order) {
      this.order = JSON.parse(options.order)
      console.log(this.order)
    }
  }
}
</script>

<style lang="scss">
.order-detail {
  padding: 20rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
  
  .header {
    background-color: #fff;
    padding: 30rpx;
    border-radius: 16rpx;
    margin-bottom: 20rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
    
    .store-info {
      flex: 1;
      .store-name {
        font-size: 36rpx;
        font-weight: bold;
        color: #333;
        margin-bottom: 10rpx;
      }
      .store-address {
        font-size: 28rpx;
        color: #666;
        display: flex;
        align-items: center;
      }
    }
    .distance {
      color: #ffb000;
      font-size: 28rpx;
    }
  }
  
  .card {
    background-color: #fff;
    border-radius: 16rpx;
    margin-bottom: 20rpx;
    padding: 0 30rpx;
    box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
    
    .card-title {
      padding: 30rpx 0;
      border-bottom: 1rpx solid #f5f5f5;
      display: flex;
      align-items: center;
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
      
      text {
        margin-left: 10rpx;
      }
    }
    
    .card-content {
      padding: 30rpx 0;
      
      .info-item {
        display: flex;
        margin-bottom: 20rpx;
        font-size: 28rpx;
        
        &:last-child {
          margin-bottom: 0;
        }
        
        .label {
          color: #999;
          width: 160rpx;
        }
        
        .value {
          color: #333;
          flex: 1;
          
          &.highlight {
            color: #ffb000;
            font-weight: bold;
          }
        }
      }
    }
  }
  
  .action-buttons {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20rpx;
    background: #fff;
    display: flex;
    justify-content: space-between;
    box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
    
    .btn {
      flex: 1;
      margin: 0 10rpx;
      height: 80rpx;
      line-height: 80rpx;
      border-radius: 40rpx;
      font-size: 32rpx;
      
      &-primary {
        background-color: #ff0000;
        color: white;
      }
      
      &-secondary {
        background-color: #f8f8f8;
        color: #333;
        border: 1rpx solid #eee;
      }
    }
  }
  
  .delivery-steps {
    .step {
      display: flex;
      align-items: center;
      margin-bottom: 30rpx;
      position: relative;
      padding-left: 50rpx;
      
      &:last-child {
        margin-bottom: 0;
      }
      
      &::before {
        content: '';
        position: absolute;
        left: 20rpx;
        top: 30rpx;
        bottom: -30rpx;
        width: 2rpx;
        background-color: #eee;
      }
      
      &:last-child::before {
        display: none;
      }
      
      &.active {
        .step-icon {
          background-color: #ffb000;
          color: white;
        }
        .step-title {
          color: #333;
          font-weight: bold;
        }
      }
      
      &.completed {
        .step-icon {
          background-color: #07C160;
          color: white;
        }
      }
    }
    
    .step-icon {
      width: 40rpx;
      height: 40rpx;
      border-radius: 50%;
      background-color: #eee;
      color: #999;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24rpx;
      position: absolute;
      left: 0;
    }
    
    .step-content {
      margin-left: 20rpx;
      
      .step-title {
        font-size: 28rpx;
        color: #999;
      }
      
      .step-time {
        display: block;
        font-size: 24rpx;
        color: #999;
        margin-top: 5rpx;
      }
    }
  }
}
</style>